<?php 
class Application_Model_DbTable_News extends Zend_Db_Table_Abstract{
	protected $_name = 'tbl_news';
	protected $_primary ='news_id';
	
	protected $_referenceMap = array (
			'tbl_news_category' => array (
					'columns' => array('news_news_category_id'),
					'refTableClass' => 'Application_Model_DbTable_NewsCategory'
			),		
	);
	
	public function getList($filters = array(),$sortType = "ASC",$sortBy = null){
		$select = $this->select();
		
		if( count($filters) > 0 ){
			foreach($filters as $key => $value){
				
				if($key=="keyword" && trim($value)!=""){
					$select->where("news_title_vi like '%".$value."%'");
				}
				
				if($key=="category" && trim($value)!="0"){
					$select->where("news_news_category_id = ?",$value);
				}
				
				if($key=="status" && trim($value)!=""){
					$select->where("news_status = ?",$value);
				}
				
				if($key=="fromDate" && $value!=null){
					$select->where('news_creation_time >= ?',$value);
				}
				
				if($key=="toDate" && $value!=null){
					$select->where('news_creation_time <= ?',$value);
				}
			}
		}
		
		if($sortBy==null){
			$sortBy = "news_creation_time";
			$sortType = "Desc";
		}
		
		$select->order($sortBy . " " . $sortType);
		return $result = $this->fetchAll($select);
	}// end get list
	
	
}












